package com.bt7274.controller;

import com.bt7274.grace.result.GraceJSONResult;
import com.bt7274.pojo.Post;
import com.bt7274.pojo.bo.PostBO;
import com.bt7274.pojo.vo.PostDetailVO;
import com.bt7274.service.PostService;
import com.bt7274.service.ReactionService;
import com.bt7274.utils.SessionUtils;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/reaction")
public class ReactionController {

    @Autowired
    private ReactionService reactionService;


    @PostMapping("/like")
    public GraceJSONResult like(@RequestParam String postId) {
        reactionService.likePost(postId);
        return GraceJSONResult.ok();
    }
    // 取消点赞
    @PostMapping("/cancelLike")
    public GraceJSONResult cancelLike(@RequestParam String postId) {
        reactionService.cancelLike(postId);
        return GraceJSONResult.ok();
    }
    // 取消点踩
    @PostMapping("/cancelDislike")
    public GraceJSONResult cancelDislike(@RequestParam String postId) {
        reactionService.cancelDislike(postId);
        return GraceJSONResult.ok();
    }
    // 点踩
    @PostMapping("/dislike")
    public GraceJSONResult dislike(@RequestParam String postId) {
        reactionService.dislikePost(postId);
        return GraceJSONResult.ok();
    }



    // 判断用户是否已点赞
    @GetMapping("/like/status/{postId}")
    public GraceJSONResult checkLikeStatus(@PathVariable("postId") String postId) {
        Boolean isLiked = reactionService.checkLikeStatus(postId);
        return GraceJSONResult.ok(isLiked);
    }

    // 判断用户是否已点踩
    @GetMapping("/dislike/status/{postId}")
    public GraceJSONResult checkDislikeStatus(@PathVariable("postId") String postId) {
        Boolean isDisliked = reactionService.checkDislikeStatus(postId);
        return GraceJSONResult.ok(isDisliked);
    }

}